﻿using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using Newtonsoft.Json;
using System.Reflection;
using System.Data;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Base.Dao
{
    public class QueryPlanUserDao : DaoService<QueryPlanUser>
    {
        public override string TableName => "FAS_QueryPlanUser";
        public override string IDColumnName => "ID";
        public override List<string> ExceptColumnName => new List<string> { "UserName" };

        public QueryPlanUserDao() : base()
        {
            DBName = "TFAS";
        }
        public override QueryPlanUser ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            var myCol = new Dictionary<string, PropertyInfo>(base.Columns);
            myCol.Remove("TopTime");
            var data = base.ConvertToObject(myCol, row);
            if (row["TopTime"] != DBNull.Value)
                data.TopTime = Convert.ToDateTime(row["TopTime"]);
            return data;
        }
        /// <summary>
        /// 获取所有默认置顶信息
        /// </summary>
        public List<QueryPlanUser> GetQueryPlanUserList(string userID)
        {
            var result = new List<QueryPlanUser>();
            List<object> objects = base.GetObjectsByFilter($"UserID='{userID}'");
            if (objects != null)
            {
                objects.ForEach(obj => result.Add(obj as QueryPlanUser));
            }
            return result;
        }
        /// <summary>
        /// 删除用户方案信息
        /// </summary>
        public void DeletePlan(string planID)
        {
            List<IDbDataParameter> paramList = new List<IDbDataParameter>();
            paramList.Add(DB.MakeInParam("@planID", TDbDataType.VarChar, planID));
            var sql = $"delete from {TableName} Where PlanID=@planID;";
            DB.ExecSqlStatement(sql, paramList.ToArray());
        }
        /// <summary>
        /// 删除置顶方案
        /// </summary>
        public void DeletePlan(string planID, string userID)
        {
            List<IDbDataParameter> paramList = new List<IDbDataParameter>();
            paramList.Add(DB.MakeInParam("@planID", TDbDataType.VarChar, planID));
            var sql = $"delete from {TableName} Where PlanID=@planID and UserID='{userID}';";
            DB.ExecSqlStatement(sql, paramList.ToArray());
        }
    }
}
